#define _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    string reverseWords(string s) {
        if (s.size() == 0)
            return s;
        for (size_t i = 0; i < s.size(); )
        {
            if (s[i] == ' ')
                i++;
            else
            {
                int j = i;
                int k = i;
                while (s[k] != ' ')
                {
                    if (s[k] == '\0')
                        break;
                    k++;
                }
                i = k;
                k--;
                for (; j < k; j++, k--)
                {
                    swap(s[j], s[k]);
                }
            }
        }
        return s;
    }
};